﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paramlist.aspx.cs" Inherits="UI.system.page.product.paramlist" %>
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<%@ Import Namespace="Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="/js/jquery.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/md5.js"></script>
    <script src="/js/swfupload.js"></script>
    <script src="/system/js/admin.js"></script>
    <script src="/system/layui/layui.js"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <style>
        td img{width:28px; height:28px; float:left; object-fit:cover}
        .left{width:200px; height:100%; float:left; cursor:pointer; border-right:1px solid #e2e2e2;}
        .left ul{width:100%; overflow:hidden;}
        .left ul .big{font-weight:bold;}
        .left ul .small{padding-left:30px;}
        .left ul .select{background:#5FB878; color:#ffffff;}
        .left ul li{width:100%; height:30px; line-height:30px; float:left; padding-left:10px;}
        .right{margin-left:200px; height:auto;}
        .right .title{width:100%; height:38px; line-height:38px; float:left; padding-left:10px; background-color:#f2f2f2; border-bottom:1px solid #e2e2e2;}
        .right .title .l{width:auto; float:left;}
        .right .title .r{width:auto; float:right;}
        .right .title .r .sort{width:80px; height:38px; float:left; padding-left:10px; padding-top:0px; margin-right:10px; border-left:1px solid #e2e2e2;}
        .right .title .r .delete{width:155px; height:38px; float:left; padding-left:10px; padding-top:0px; border-left:1px solid #e2e2e2;}
        .right .line{width:100%; height:38px; line-height:38px; float:left; padding-left:10px; border-bottom:1px solid #e2e2e2;}
        .right .line .l{width:auto; float:left;}
        .right .line .r{width:auto; float:right;}
        .right .line .r .sort{width:80px; height:38px; float:left; padding-left:10px; padding-top:5px; margin-right:10px; border-left:1px solid #e2e2e2;}
        .right .line .r .delete{width:155px; height:38px; float:left; padding-left:10px; padding-top:0px; border-left:1px solid #e2e2e2;}
        .nocategory{width:100%; height:50px; line-height:50px; text-align:center;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar">
        <div class="layer-toolbar-left" style="padding-left:188px;">
        <%=MenuDAL.Power("Save") %>
        <a href="javascript:void(0)" class="layui-btn layui-btn-small layui-btn-normal" onclick="Save(this,0)">新增参数</a>
        </div>
        <div class="layer-toolbar-right">
            <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
        <div class="left">
            <ul>
                <%
                    int index1 = 0;
                    foreach (CategoryInfo parent in category1){
                    index1++;
                %>
                <li class='big <%=index1==1 && category2.Count==0 ? "select":"" %>' category1id="<%=parent.ID %>" category2id="0"><%=parent.Name %></li>
                <%
                    List<CategoryInfo> childlist = categorylist.Where(x => x.ParentID == parent.ID).ToList();
                    int index2 = 0;
                    foreach(CategoryInfo child in childlist){
                    index2++;
                %>
                <li class='small <%=index2==1 && category2.Count!=0 ? "select":"" %>' category1id="<%=parent.ID %>" category2id="<%=child.ID %>"><%=child.Name %></li>
                <%}}
                    if(category1.Count==0){    
                %>
                <p class='nocategory'>请先添加商品分类</p>
                <%} %>
            </ul>
        </div>
        <div class="right">
            <div class="title"><div class="l">名称</div><div class="r"><div class="sort">顺序</div><div class="delete">操作</div></div></div>
            <div id="layer-table"></div>
        </div>
    </div>
    <script id="data-table" type="text/html">
      {{#  layui.each(d, function(index, d){ }}
        {{# if(d.Type==1){ }}
        <div class="line" style="background:#ecfbef;"><div class="l">{{d.Name}}</div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'param')" /></div><div class="delete"><%=MenuDAL.Powers("Edit,Delete") %><a class="layui-btn layui-btn-mini layui-btn-normal" onclick="Save(this,0)" parentid="{{d.ID}}">添加</a></div></div></div>
        {{# $.each(d.ChildList,function(i,d){ }}
        <div class="line"><div class="l">&nbsp;&nbsp;&nbsp;&nbsp;{{d.Name}}</div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'param')" /></div><div class="delete"><%=MenuDAL.Powers("Edit,Delete") %></div></div></div>
        {{# }); }}
        {{# } }}
        {{# if(d.Type==2 && d.ParentID==0){ }}
        <div class="line"><div class="l">{{d.Name}}</div><div class="r"><div class="sort"><input class="layui-input tdtext" value="{{d.Sort}}" onblur="ReSort(this,{{d.ID}},'param')" /></div><div class="delete"><%=MenuDAL.Powers("Edit,Delete") %></div></div></div>
        {{# } }}
      {{# }); }}
      </script>
    </form>

    <script>
        layui.use(["form", "table"], function () {
            var $ = layui.jquery, form = layui.form;
            table = layui.table;
            Init_Pager();
        });

        function Init_Pager() {
            var data = {};
            data.act = "Find_Param";
            data.category1id = $("#iframe ul .select").attr("category1id");
            data.category2id = $("#iframe ul .select").attr("category2id");
            data.sign = GetSign(data.act);
            Loading2();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Data2(json.data);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };

        function Save(o, id) {
            if ($("#iframe ul .select").length == 0) {
                LayerBox.Error("请选择左侧分类菜单");
                return;
            }
            var type = 0;
            var parentid = 0;
            if ($(o).html() == "新增参数组") {
                type = 1;
            } else {
                type = 2;
            }
            if ($(o).attr("parentid")) {
                parentid = $(o).attr("parentid");
            } else {
                parentid = 0;
            }
            Ajax.Get("/system/page/product/paramadd.aspx?id=" + id + "&type=" + type + "&parentid=" + parentid, function (html) {
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title, html, "400px", "240px", null, function (form) {
                    var data = form;
                    data.act = "Save_Param";
                    data.id = id;
                    data.parentid = parentid;
                    data.type = type;
                    data.category1id = $("#iframe ul .select").attr("category1id");
                    data.category2id = $("#iframe ul .select").attr("category2id");
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    Init_Pager();
                                } else {
                                    Init_Pager();
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        function Delete(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_Param");
            });
        };

        $("#iframe .left li").click(function () {
            $(this).addClass("select").siblings().removeClass("select");
            Init_Pager();
        });
</script>
</body>
</html>
